<template>
    <div class="seach">
      <div class="seach_body">
        <!-- 开始 -->
        <el-table :data="this.users_Info" border stripe><!-- 带边框、斑马纹 -->
          <!-- <el-table-column type="index"></el-table-column> -->
          <el-table-column label="书架编号" prop="id"></el-table-column>
          <el-table-column label="书名" prop="bookName"></el-table-column>
          <el-table-column label="作者" prop="author"></el-table-column>
          <el-table-column label="读者编号" prop="userId"></el-table-column>
          <el-table-column label="借书编号" prop="bookId"></el-table-column>
          <el-table-column label="加入时间" prop="addtime"></el-table-column>
          <!-- <el-table-column label="身份" prop="ismaind"></el-table-column>  -->

          <el-table-column label="操作" >
             <!-- //width="100px" -->
              <template slot-scope="scope">
                  <el-tooltip effect="dark" content="删除" placement="top">
                    <el-button type="danger" icon="el-icon-delete" @click="updata_delete(scope.row)" size="mini"></el-button>
                  </el-tooltip>
              </template>
          </el-table-column>
        <!-- </div> -->
        </el-table>
        <!-- 结束 -->
        <Cancel_sub v-if="this.delete" :tocancel="this.tocancel"></Cancel_sub>
      </div>
      <div class="seach_bottom">
        <div class="bottom_buttons">
          <el-pagination
           background
           layout="prev, pager, next"
            @current-change="handleSizeChange"   
           @prev-click="handleCurrentChange"
           @next-click="handleCurrentChange"
           :total=this.total>
          </el-pagination>
        </div>
      </div>
    </div>
  </template>
  <script>
  import Cancel_sub from '../components/Cancel_sub.vue'
  export default({
    data(){
        return{
          key:0,
            notice:false,
            delete:false, 
             total:0,
             id:0,
            users_Info:[
            ],
            tonote:{},
            test:[{id:"20100140205",bookId:"123455",userId:"kuangfeng",bookName:"男",subtime:"123456@qq.com",},
          ]
        }
    },
    components:{
      Cancel_sub
    },
    methods:{
      async getsubList() {
        this.axios.get('http://192.168.43.171:8081/bookshelf/page', {
                        params:{
                         key: this.key,        // 参数 id
                        }
                     // 参数 name
                  }).then( (response)=> {
                    console.log(response.data);
                    console.log(response);
                    // this.total = res.data.total;
                    this.users_Info=response.data.data;
                    this.total=response.data.maxpage*10
                    console.log("1234");
                    console.log(this.users_Info);
                  }).catch(function (error) {
                    console.log(error);
                  });
      // this.userList = res.data.users;
      // this.total = res.data.total;
      },
      // 当前页
      handleSizeChange(val) {
        this.key=val
        console.log(`当前 ${val} 页`);
        this.getsubList();
        // this.axios.get('http://192.168.43.171:8081/bookshelf/page', {
        //                 params:{
        //                  key:this.key,        // 参数 id
        //                 }
        //              // 参数 name
        //           }).then( (response)=> {
        //             console.log(response.data);
        //             console.log(response);
        //             // this.total = res.data.total;
        //             this.users_Info=response.data.page;
        //             this.total=response.data.maxpage*10
        //             console.log("1234");
        //             console.log(this.users_Info);
        //           }).catch(function (error) {
        //             console.log(error);
        //           });
      },
      // 下一页或者上一页
      handleCurrentChange(val) {
        this.key=val
        console.log(`去第 ${val}页`);
        this.getsubList();
        // this.axios.get('http://192.168.43.171:8081/bookshelf/page', {
        //                 params:{
        //                  key:this.key,        // 参数 id
        //                 }
        //              // 参数 name
        //           }).then( (response)=> {
        //             console.log(response.data);
        //             console.log(response);
        //             // this.total = res.data.total;
        //             this.users_Info=response.data.page;
        //             this.total=response.data.maxpage*10
        //             console.log("1234");
        //             console.log(this.users_Info);
        //           }).catch(function (error) {
        //             console.log(error);
        //           });
      },

      // 删除记录
      updata_delete(row){
        this.delete=true;
        this.id=row.bookId;
      },
      // 删除图书后被调用的delete调用函数
      tocancel(){
        console.log("取消订阅信息删除被调用了");
        // 
        this.axios.get('http://192.168.43.171:8081/bookshelf/delete', {
                        params:{
                         id: this.id,        // 参数 id
                        }
                     // 参数 name
                  }).then( (response)=> {
                    // console.log(response.data);
                    // console.log(response);
                    this.users_Info=response.data.page;
                    // console.log("1234");
                    this.getsubList();
                    // console.log(this.users_Info);
                  }).catch(function (error) {
                    console.log(error);
                  });
                  // 
      }
      // 
      
    },
    mounted(){
          // 删除全局事件总线
          this.$bus.$on ('bus_delete_cancel', (data) => {
            this.delete=data;
            // console.log(data);
            if(data==1){
              this.delete=false
            }
          }),
          this.$bus.$on ('bus_delete', (data) => {
            // this.delete=data;
            console.log(data);
            if(data==1){
              this.delete=false
            }
          })
          this.getsubList()
      },
      beforeDestroy(){
          // this.$bus.$off('bus_delete_cancel')
          this.$bus.$off('bus_delete')
        },
  })
  </script>
  <style lang="less" scoped>
  .seach{
    width: 100%;
    height: 100%;
    position: absolute;
    .seach_seach{
      position: absolute;
      right: 50px;
      height: 6%;
      width: 30%;
      // background-color: #67c58b;
      .seach_input{
         position: absolute;
         width: 70%;
         top: 4px;
      }
      .input_buttons{
       position: absolute;
       top: 16%;
       right: 11%;
      }
    }
    .seach_body{
    // background-color: aquamarine;
    // background-color: rgb(245, 243, 243);
    background-color: #fff;
    position: absolute;
    top: 7%;
    height: 80%;
    width: 100%;
    td{
      // background-color: rgb(245, 243, 243);
      // background-color: rgba(247, 248, 243,0.95);
      background-color: #fff;
      th{
        // background-color: rgb(245, 243, 243);
      }
  
    }
    }
  
    .seach_bottom{
      // background-color: #5f9ca1;
      height: 10%;
      width: 100%;
      bottom: 1%;
      position: absolute;
      .bottom_buttons{
        position: absolute;
        top: 32%;
        height: 40%;
        width: 20%;
        left: 25%;
        // transform: translate(-50%,-50%);
        // background-color: bisque;
      }
  
    }
  }
 
  </style>